package com.yd.app.mapper.jewellery.jewelleryPageMapper;

import com.yd.app.mapper.provider.CartProvider;
import com.yd.domain.business.ShoppingCart;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 * @Author: zy
 * @Desc: 电脑端的购物车
 * @Date:  2018/5/14
 * @Param
 */
@Repository
public interface WebSiteCartMapper {
    /**
     * 添加
     */
    @Insert("insert into business_shopping_cart (userId, goodsId,goodsWeightId, addTime, number,content) values (#{shoppingCart.userId}, " +
            "#{shoppingCart.goodsId},#{shoppingCart.goodsWeightId}, #{shoppingCart.addTime}, #{shoppingCart.number}, #{shoppingCart.content})" +
            "ON DUPLICATE KEY UPDATE number=#{shoppingCart.number},addTime= #{shoppingCart.addTime} ")
    void addCart(@Param("shoppingCart") ShoppingCart shoppingCart);
    /**
     * @Author: zy
     * @Desc: 查询某一购物车是否存在
     * @Date:  2018/4/8
     */
    @Select("select * from business_shopping_cart where userId = #{userId} and goodsId = #{goodsId} and goodsWeightId=#{goodsWeightId} " )
    ShoppingCart getCartByUGId(@Param("userId") String userId, @Param("goodsId") String goodsId, @Param("goodsWeightId") String goodsWeightId);
    /**
     * 修改
     */
  /*  @Update("update business_shopping_cart set addTime = #{shoppingCart.addTime}, number = #{shoppingCart.number} where userId = #{shoppingCart.userId}")
    void updateCart(@Param("shoppingCart") ShoppingCart shoppingCart);*/

    /**
     * 删除
     */
    @Delete("delete from business_shopping_cart where userId = #{userId} and goodsId = #{goodsId} and goodsWeightId=#{goodsWeightId} ")
    void deleteCar(@Param("userId") String userId, @Param("goodsId") String goodsId, @Param("goodsWeightId") String goodsWeightId);

    /**
     *查询用户购物车信息
     */
    @Select("Select c.*,g.*,bgw.minWeight,bgw.maxWeight,bgw.jgf from business_shopping_cart c left join business_goods g on c.goodsId=g.id left join business_goods_weight bgw on c.goodsWeightId=bgw.id   where c.userId = #{userId}")
    List<ShoppingCart> getListCart(@Param("userId") String userId);


    /**
     * 查询总条数
     *
     */
    @SelectProvider(method = "getCartListCount", type = CartProvider.class)
    int getListCartCount(@Param("shoppingCart") ShoppingCart shoppingCart);

    /**
     * 查询
     */
    @Select("Select * from business_shopping_cart where userId = #{userId}")
    ShoppingCart getCart(@Param("userId") String userId);

    /**
     * 修改商品购买刷量
     * @param goodsId
     * @param number
     */
    @Update("update business_shopping_cart set number=#{number} where userId=#{userId} and goodsId=#{goodsId} ")
    void updateCartNumber(@Param("userId") String userId, @Param("goodsId") String goodsId, @Param("number") int number);
}
